<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理</title>
<script type="text/javascript">
	
	function delMessage(){
		//获得选中数据对象
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];//要删除的序号组合
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].messageid);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				//ajax提交 delIds
				$.post("delMessage",{messageids:ids},function(result){
					if(result){
						$.messager.alert("系统提示","您已成功删除<font color=red>"+selectedRows.length+"</font>条数据！");
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	
	//查询符合条件的用户
	function searchMessage(){
		$('#dg').datagrid('load',{
			messageid:$('#messageid').val(),
			messageuserid:$('#messageuserid').val(),
			messagecontent:$('#messagecontent').val(),
			smessagetime:$('#smessagetime').datetimebox("getValue"),
			emessagetime:$('#emessagetime').datetimebox("getValue"),
		});
	}
	function openMessageModifyDialog(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1){
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		var row=selectedRows[0];
		$("#dlg").dialog("open").dialog("setTitle","编辑留言板信息");
		$("#mmessageid").val(row.messageid);
		$("#mmessageuserid").val(row.messageuserid);
		$("#mmessagecontent").val(row.messagecontent);
		$("#mmessagetime").datetimebox("setValue",row.messagetime);

	}	
	function saveMessage(){
		$("#fm").form("submit",{
			url:"updateMessage",
			onSubmit:function(){
				if($('#mmessagecontent').val()==""){
					$.messager.alert("系统提示","请输入留言内容");
					return false;
				}
				if($('#mmessagetime').datetimebox("getValue")==""){
					$.messager.alert("系统提示","请选择时间");
					return false;
				}
				return $(this).form("validate");
			},
			success:function(result){
				if(result){
					$.messager.alert("系统提示","保存成功");
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败");
					return;
				}
			}
		});
	}
	
	//关闭对话框
	function closeMessageDialog(){
		$("#dlg").dialog("close");
	}
</script>
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/icon.css" />
<script type="text/javascript" src="../easyui-1.5/jquery.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin:5px">
	<table id="dg" title="留言信息" class="easyui-datagrid" fitColumns="true" striped="true"
	 pagination="true" rownumbers="true" url="getMessageList" fit="true" toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="messageid" width="100" align="center">留言编号</th>
				<th field="messageuserid" width="100" align="center">留言账号</th>
				<th field="messagecontent" width="200" align="center">留言内容</th>
				<th field="messagetime" width="100"  align="center">留言时间</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openMessageModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:delMessage()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			<form  method="post">
			&nbsp;留言编号：&nbsp;<input type="text" name="messageid" id="messageid" size="8"/>
			&nbsp;留言账号：&nbsp;<input type="text" name="messageuserid" id="messageuserid" size="8"/>
			&nbsp;留言内容：&nbsp;<input type="text" name="messagecontent" id="messagecontent" size="8"/>
			&nbsp;留言时间：&nbsp;<input class="easyui-datetimebox" name="smessagetime" id="smessagetime" editable="false" size="15"/>->
			<input class="easyui-datetimebox" name="emessagetime" id="emessagetime" editable="false" size="15"/>
			<a href="javascript:searchMessage()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</form>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 550px;height: 240px;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
			<table cellspacing="5px;">
				<tr>		
					<td>留言编号：</td>
					<td><input type="text" name="messageid" id="mmessageid" class="easyui-validatebox" required="true" readonly/></td>
					<td>留言账号：</td>
					<td><input type="text" name="messageuserid" id="mmessageuserid" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>留言内容：</td>
					<td><input type="text" name="messagecontent" id="mmessagecontent" class="easyui-validatebox" required="true" /></td>
					<td>留言时间：</td>
					<td>
					<input class="easyui-datetimebox" name="messagetime" id="mmessagetime" editable="false" size="15"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:saveMessage()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeMessageDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
	
</body>
</html>